From aba1f12c1495179ad7a3c39acb1fcfd5603c275a Mon Sep 17 00:00:00 2001 From: "kfraser@dhcp93.uk.xensource.com" Date: Mon, 19 Jun 2006 13:06:10 +0100 Subject: [PATCH] [XEN] New function dump_execution_state() displays current register and stack state of local CPU. Use this to extend the 'd' debug key to be more useful. Signed-off-by: Keir Fraser --- xen/arch/x86/traps.c | 15 +++++++++++++++ xen/common/keyhandler.c | 20 +++++++++++++++++++- xen/include/asm-x86/processor.h | 5 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index 199ad50b72..6d442ed4ca 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -487,6 +487,21 @@ asmlinkage int do_invalid_op(struct cpu_user_regs *regs) if ( unlikely(!guest_mode(regs)) ) { + char sig[5]; + /* Signature (ud2; .ascii "dbg") indicates dump state and continue. */ + if ( (__copy_from_user(sig, (char *)regs->eip, sizeof(sig)) == 0) && + (memcmp(sig, "\xf\xb""dbg", sizeof(sig)) == 0) ) + { + show_execution_state(regs); + regs->eip += sizeof(sig); + return EXCRET_fault_fixed; + } + printk("%02x %02x %02x %02x %02x\n", + (unsigned char)sig[0], + (unsigned char)sig[1], + (unsigned char)sig[2], + (unsigned char)sig[3], + (unsigned char)sig[4]); DEBUGGER_trap_fatal(TRAP_invalid_op, regs); show_execution_state(regs); panic("CPU%d FATAL TRAP: vector = %d (invalid opcode)\n", diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index aea0f1a787..3f286e3ae6 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -87,10 +87,28 @@ static void show_handlers(unsigned char key) key_table[i].desc); } +static void __dump_execstate(void *unused) +{ + dump_execution_state(); +} + static void dump_registers(unsigned char key, struct cpu_user_regs *regs) { + unsigned int cpu; + printk("'%c' pressed -> dumping registers\n", key); - show_execution_state(regs); + + /* Get local execution state out immediately, in case we get stuck. */ + printk("\n*** Dumping CPU%d state: ***\n", smp_processor_id()); + show_execution_state(regs); + + for_each_online_cpu ( cpu ) + { + if ( cpu == smp_processor_id() ) + continue; + printk("\n*** Dumping CPU%d state: ***\n", cpu); + on_selected_cpus(cpumask_of_cpu(cpu), __dump_execstate, NULL, 1, 1); + } } static void halt_machine(unsigned char key, struct cpu_user_regs *regs) diff --git a/xen/include/asm-x86/processor.h b/xen/include/asm-x86/processor.h index 75d0772fef..c6b3247763 100644 --- a/xen/include/asm-x86/processor.h +++ b/xen/include/asm-x86/processor.h @@ -535,6 +535,11 @@ void show_execution_state(struct cpu_user_regs *regs); void show_page_walk(unsigned long addr); asmlinkage void fatal_trap(int trapnr, struct cpu_user_regs *regs); +/* Dumps current register and stack state. */ +#define dump_execution_state() \ + /* NB. Needs interrupts enabled else we end up in fatal_trap(). */ \ + __asm__ __volatile__ ( "pushf ; sti ; ud2 ; .ascii \"dbg\" ; popf" ) + extern void mtrr_ap_init(void); extern void mtrr_bp_init(void); -- 2.30.2